package com.example.demo.test;/**
 * Created by kete on 2018-12-03.
 */

import com.alibaba.fastjson.JSONObject;
import com.google.common.io.Files;
import org.apache.ibatis.session.SqlSession;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

import static com.example.demo.test.MybatisUtil.SERVER_URL;
import static java.lang.System.err;

/**
 * 作者：kete
 * 创建时间：2018-12-03 15:14
 * 功能描述：
 * 版本：
 */
public class UrlParseTask implements Runnable {


    private String accountNum;

    public UrlParseTask(String accountNum) {

        this.accountNum = accountNum;
    }

    @Override
    public void run() {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        TempUrlMapper mapper = sqlSession.getMapper(TempUrlMapper.class);


        File file = new File("d:\\temp\\test"+accountNum+".txt");

        try {
            String json = Files.toString(file, Charset.forName("UTF-8"));

            List<TempUrl> list = JSONObject.parseArray(json,TempUrl.class);

            mapper.updateBatch(list);


        } catch (IOException e) {
            e.printStackTrace();
        }

        sqlSession.commit();

        sqlSession.close();


//        mapper.updateBatch(list);


        System.out.println("线程"+accountNum+"-----------更新完成");


    }
}
